<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <div v-html='html'>123</div>
    <div v-power='toPower'></div>
    <div :class="classObj">计算属性:共借出{{lend}}，已还{{repay}}，还剩{{remaining}}</div>
    <input v-on:keyup.page-down="onPageDown">
    <div>年龄：{{age}}</div>
    <subHello @ageAdd="ageAdd" :subAge="age"/>
    <page-a/>
    <page-b/>
  </div>
</template>

<script>
  import subHello from './subHello'
  import pageA from './pageA'
  import pageB from './pageB'

  export default {
    name: 'HelloWorld',
    props: {
      msg: String,
    },
    data () {
      return {
        html: '<div style="color:red">测试html</div>',
        toPower: 21,
        lend: 1000,
        repay: 125,
        classObj: {
          green: true,
          underLine: true
        },
        age: 10
      }
    },
    methods: {
      onPageDown () {
        console.log('“下一页”按键触发')
      },
      ageAdd (param) {
        this.age++;
        console.log(param)
      },
    },
    computed: {
      remaining () {
        return this.lend - this.repay
      }
    },
    directives: {
      power: {
        bind (el, binding) {
          el.innerHTML = Math.pow(binding.value, 2)
        }
      }
    },
    components: {
      subHello,
      pageA,
      pageB
    },
    // store:storeModule
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .green {
    color: green;
  }

  .underLine {
    text-decoration: underline;
  }

  h3 {
    margin: 40px 0 0;
  }

  ul {
    list-style-type: none;
    padding: 0;
  }

  li {
    display: inline-block;
    margin: 0 10px;
  }

  a {
    color: #42b983;
  }
</style>
